home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / wnos5src.zip / NR4.H < prev    next >
Text File  |  1993-08-09  |  9KB  |  264 lines

  1. #ifndef    NR4MAXCIRC
  2.  
  3. #include "mbuf.h"
  4. #include "timer.h"
  5. #include "ax25.h"
  6.  
  7. /* nr4.h:  defines for netrom layer 4 (transport) support */
  8.  
  9. /* compile-time limitations */
  10.  
  11. #define    NR4MAXCIRC    20        /* maximum number of open circuits */
  12. #define NR4MAXWIN    127        /* maximum window size, send and receive */
  13.  
  14. /* protocol limitation: */
  15.  
  16. #define    NR4MAXINFO    236        /* maximum data in an info packet */
  17.  
  18. /* sequence number wraparound mask */
  19.  
  20. #define NR4SEQMASK    0xff    /* eight-bit sequence numbers */
  21.  
  22. /* flags in high nybble of opcode byte */
  23.  
  24. #define    NR4CHOKE    0x80
  25. #define    NR4NAK        0x40
  26. #define    NR4MORE        0x20    /* The "more follows" flag for */
  27.                             /* pointless packet reassembly */
  28.  
  29. /* mask for opcode nybble */
  30.  
  31. #define    NR4OPCODE    0x0f
  32.  
  33. /* opcodes */
  34.  
  35. #define NR4OPPID    0        /* protocol ID extension to network layer */
  36. #define    NR4OPCONRQ    1        /* connect request */
  37. #define    NR4OPCONAK    2        /* connect acknowledge */
  38. #define    NR4OPDISRQ    3        /* disconnect request */
  39. #define    NR4OPDISAK    4        /* disconnect acknowledge */
  40. #define    NR4OPINFO    5        /* information packet */
  41. #define    NR4OPACK    6        /* information ACK */
  42. #define NR4NUMOPS    7        /* number of transport opcodes */
  43.  
  44. /* minimum length of NET/ROM transport header */
  45.  
  46. #define    NR4MINHDR    5
  47.  
  48. /* host format net/rom transport header */
  49.  
  50. struct nr4hdr {
  51.     unsigned char opcode ;        /* opcode and flags */
  52.     unsigned char yourindex ;    /* receipient's circuit index */
  53.     unsigned char yourid ;        /* receipient's circuit ID */
  54.  
  55.     union {
  56.  
  57.         struct {                /* network extension */
  58.             unsigned char family ;    /* protocol family */
  59.             unsigned char proto ;    /* protocol within family */
  60.         } pid ;
  61.  
  62.         struct {                /* connect request */
  63.             unsigned char myindex ;    /* sender's circuit index */
  64.             unsigned char myid ;    /* sender's circuit ID */
  65.             unsigned char window ;    /* sender's proposed window size */
  66.             char user[AXALEN] ;    /* callsign of originating user */
  67.             char node[AXALEN] ;    /* callsign of originating node */
  68.         } conreq ;
  69.  
  70.         struct {                /* connect acknowledge */
  71.             unsigned char myindex ;    /* sender's circuit index */
  72.             unsigned char myid ;    /* sender's circuit ID */
  73.             unsigned char window ;     /* accepted window size */
  74.         } conack ;
  75.  
  76.         struct {                /* information */
  77.             unsigned char txseq ;    /* sender's tx sequence number */
  78.             unsigned char rxseq ;    /* sender's rx sequence number */
  79.         } info ;
  80.  
  81.         struct {                /* information acknowledge */
  82.             unsigned char rxseq ;    /* sender's rx sequence number */
  83.         } ack ;
  84.  
  85.     } u ;    /* End of union */
  86.  
  87. } ;
  88.  
  89. /* The netrom circuit pointer structure */
  90.  
  91. struct nr4circp {
  92.     unsigned char cid ;            /* circuit ID; incremented each time*/
  93.                                 /* this circuit is used */
  94.     struct nr4cb *ccb ;            /* pointer to circuit control block, */
  95.                                 /*  NULLNR4CB if not in use */
  96. } ;
  97.  
  98. /* The circuit table: */
  99.  
  100. extern struct nr4circp Nr4circuits[NR4MAXCIRC] ;
  101.  
  102. /* A netrom send buffer structure */
  103.  
  104. struct nr4txbuf {
  105.     struct timer tretry ;        /* retry timer */
  106.     unsigned retries ;            /* number of retries */
  107.     struct mbuf *data ;            /* data sent but not acknowledged */
  108. } ;
  109.  
  110. /* A netrom receive buffer structure */
  111.  
  112. struct nr4rxbuf {
  113.     unsigned char occupied ;    /* flag: buffer in use */
  114.     struct mbuf *data ;         /* data received out of sequence */
  115. } ;
  116.  
  117. /* address structure used in struct nr4cb */
  118. #ifndef SOCK_STREAM
  119. struct nr4_addr {
  120.     char user[AXALEN];
  121.     char node[AXALEN];
  122. };
  123. #endif
  124. #define    NULLNRADDR    (struct nr4_addr *)0
  125.  
  126. /* The netrom circuit control block */
  127.  
  128. struct nr4cb {
  129.     unsigned mynum ;            /* my circuit number */
  130.     unsigned myid ;                /* my circuit ID */
  131.     unsigned yournum ;            /* remote circuit number */
  132.     unsigned yourid ;            /* remote circuit ID */
  133.     struct nr4_addr remote ;        /* address of remote node */
  134.     struct nr4_addr local ;            /* our own address */
  135.  
  136.     unsigned window ;            /* negotiated window size */
  137.  
  138.     /* Data for round trip timer calculation and setting */
  139.  
  140.     int32 srtt ;                    /* Smoothed round trip time */
  141.     int32 mdev ;                    /* Mean deviation in round trip time */
  142.     unsigned blevel ;            /* Backoff level */
  143.     unsigned txmax ;            /* The maximum number of retries among */
  144.                                 /* the frames in the window.  This is 0 */
  145.                                 /* if there are no frames in the window. */
  146.                                 /* It is used as a baseline to determine */
  147.                                 /* when to increment the backoff level. */
  148.  
  149.     /* flags */
  150.  
  151.     char clone ;                /* clone this cb upon connect */
  152.     char choked ;                /* choke received from remote */
  153.     char qfull ;                /* receive queue is full, and we have */
  154.                                 /* choked the other end */
  155.     char naksent ;                /* a NAK has already been sent */
  156.  
  157.     /* transmit buffers and window variables */
  158.  
  159.     struct nr4txbuf *txbufs ;    /* pointer to array[windowsize] of bufs */
  160.     unsigned char nextosend ;    /* sequence # of next frame to send */
  161.     unsigned char ackxpected ;    /* sequence number of next expected ACK */
  162.     unsigned nbuffered ;        /* number of buffered TX frames */
  163.     struct mbuf *txq ;            /* queue of unsent data */
  164.  
  165.     /* receive buffers and window variables */
  166.  
  167.     struct nr4rxbuf *rxbufs ;    /* pointer to array[windowsize] of bufs */
  168.     unsigned char rxpected ;    /* # of next receive frame expected */
  169.     unsigned char rxpastwin ;    /* top of RX window + 1 */
  170.     struct mbuf *rxq ;            /* "fully" received data queue */
  171.  
  172.     /* Connection state */
  173.  
  174.     int state ;                    /* connection state */
  175. #define NR4STDISC    0            /* disconnected */
  176. #define NR4STCPEND    1            /* connection pending */
  177. #define NR4STCON    2            /* connected */
  178. #define    NR4STDPEND    3            /* disconnect requested locally */
  179. #define NR4STLISTEN    4            /* listening for incoming connections */
  180.  
  181.     int dreason ;                /* Reason for disconnect */
  182. #define NR4RNORMAL    0            /* Normal, requested disconnect */
  183. #define NR4RREMOTE    1            /* Remote requested */
  184. #define    NR4RTIMEOUT    2            /* Connection timed out */
  185. #define    NR4RRESET    3            /* Connection reset locally */
  186. #define NR4RREFUSED    4            /* Connect request refused */
  187.  
  188.     /* Per-connection timers */
  189.  
  190.     struct timer tchoke ;        /* choke timeout */
  191.     struct timer tack ;            /* ack delay timer */
  192.     struct timer tcd ;            /* connect/disconnect timer */
  193.     struct timer inactivity;    /* inactivity timer */
  194.  
  195.     unsigned cdtries ;            /* Number of connect/disconnect tries */
  196.     
  197.     void (*r_upcall) __ARGS((struct nr4cb *,int16));
  198.                     /* receive upcall */
  199.     void (*t_upcall) __ARGS((struct nr4cb *,int16));
  200.                     /* transmit upcall */
  201.     void (*s_upcall) __ARGS((struct nr4cb *,int,int));
  202.                     /* state change upcall */
  203.     int user ;            /* user linkage area */
  204. } ;
  205.  
  206. #define    NULLNR4CB    (struct nr4cb *)0
  207.  
  208. /* Some globals */
  209.  
  210. extern unsigned short Nr4window ;    /* The advertised window size, in frames */
  211. extern int16 Nr4irtt ;                /* The initial round trip time */
  212. extern unsigned short Nr4retries ;    /* The number of times to retry */
  213. extern int16 Nr4acktime ;        /* How long to wait until ACK'ing */
  214. extern char *Nr4states[] ;        /* NET/ROM state names */
  215. extern char *Nr4reasons[] ;        /* Disconnect reason names */
  216. extern unsigned short Nr4qlimit ;        /* max receive queue length before CHOKE */
  217. extern int16 Nr4choketime ;        /* CHOKEd state timeout */
  218. extern char Nr4user[AXALEN];    /* User callsign in outgoing connects */
  219.  
  220. /* function definitions */
  221.  
  222. /* In nr4hdr.c: */
  223. int ntohnr4 __ARGS((struct nr4hdr *, struct mbuf **));
  224. struct mbuf *htonnr4 __ARGS((struct nr4hdr *));
  225.  
  226. /* In nr4subr.c: */
  227. void free_n4circ __ARGS((struct nr4cb *));
  228. struct nr4cb *get_n4circ __ARGS((int, int));
  229. int init_nr4window __ARGS((struct nr4cb *, unsigned));
  230. int nr4between __ARGS((unsigned, unsigned, unsigned));
  231. struct nr4cb *match_n4circ __ARGS((int, int,char *,char *));
  232. struct nr4cb *new_n4circ __ARGS((void));
  233. void nr4defaults __ARGS((struct nr4cb *));
  234. int nr4valcb __ARGS((struct nr4cb *));
  235.  
  236. /* In nr4.c: */
  237. void nr4input __ARGS((struct nr4hdr *hdr,struct mbuf *bp));
  238. int nr4output __ARGS((struct nr4cb *));
  239. void nr4sbuf __ARGS((struct nr4cb *, unsigned));
  240. void nr4sframe __ARGS((char *, struct nr4hdr *, struct mbuf *));
  241. void nr4state __ARGS((struct nr4cb *, int));
  242.  
  243. /* In nr4timer.c */
  244. void nr4ackit __ARGS((void *));
  245. void nr4cdtimeout __ARGS((void *));
  246. void nr4txtimeout __ARGS((void *));
  247. void nr4unchoke __ARGS((void *));
  248.  
  249. /* In nr4user.c: */
  250. void disc_nr4 __ARGS((struct nr4cb *));
  251. int kick_nr4 __ARGS((struct nr4cb *));
  252. struct nr4cb *open_nr4 __ARGS((struct nr4_addr *, struct nr4_addr *, int,
  253.   void (*)(), void (*)(), void (*)(),int));
  254. struct mbuf *recv_nr4 __ARGS((struct nr4cb *, int16));
  255. void reset_nr4 __ARGS((struct nr4cb *));
  256. int send_nr4 __ARGS((struct nr4cb *, struct mbuf *));
  257.  
  258. /* In nrcmd.c: */
  259. void nr4_state __ARGS((struct nr4cb *, int, int));
  260.  
  261. #endif    /* NR4MAXCIRC */
  262.  
  263.  
  264.